<template>
  <div class="main">
    <div :class="[this.wineryDetail.wineryStatus==0 ? 'bhead magb' : 'head magb']">{{this.wineryDetail.name}} <span v-if="this.wineryDetail.wineryStatus!==1" id="s0">
      异常状态!
    </span></div>
    <div class="base magb">
      <div class="base_text">
        <div></div>
        <div>
          <el-button @click="edit(wineryId)">编辑</el-button>
          <el-button v-if="this.wineryDetail.wineryStatus==1 " @click="wineryStatus0()">设为异常</el-button>
          <el-button v-else @click="wineryStatus1()">恢复正常</el-button>
        </div>
      </div>
      <div class="magb">
        <el-descriptions title="基本信息" direction="vertical" :column="10" border>
          <el-descriptions-item label="酒企名称">{{this.wineryDetail.name ? this.wineryDetail.name : "暂无数据" }}
          </el-descriptions-item>
          <el-descriptions-item label="法人">{{this.wineryDetail.legalPerson ? this.wineryDetail.legalPerson : "暂无数据" }}
          </el-descriptions-item>
          <el-descriptions-item label="联系人">{{this.wineryDetail.linkman ? this.wineryDetail.linkman : "暂无数据" }}
          </el-descriptions-item>
          <el-descriptions-item label="联系方式">{{this.wineryDetail.contactWay ? this.wineryDetail.contactWay : "暂无数据" }}
          </el-descriptions-item>
          <el-descriptions-item label="签约种类">
            {{this.wineryDetail.contractTypes ? this.wineryDetail.contractTypes : "暂无数据" }}
          </el-descriptions-item>
          <el-descriptions-item label="入库总销量">{{this.wineryDetail.sales?this.wineryDetail.sales : "暂无数据" }}
          </el-descriptions-item>
          <el-descriptions-item label="现总库存">{{this.wineryDetail.stocks?this.wineryDetail.stocks : "暂无数据" }}
          </el-descriptions-item>
          <el-descriptions-item label="上架种类数量">{{this.wineryDetail.shelvesNum?this.wineryDetail.shelvesNum : "暂无数据" }}
          </el-descriptions-item>
          <!-- <el-descriptions-item label="状态">{{this.wineryDetail.status?this.wineryDetail.status : "暂无数据" }}
          </el-descriptions-item> -->
          <el-descriptions-item label="入驻来源">{{this.wineryDetail.source?this.wineryDetail.source : "暂无数据" }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <div class="magb">
        <el-descriptions title="材料资质" direction="vertical" :column="14" border>
          <el-descriptions-item label="营业执照"><span class="pointer"
              @click="picturePreview(wineryDetail.businessLicense)">查看</span></el-descriptions-item>
          <el-descriptions-item label="法人身份证(正)"><span class="pointer"
              @click="picturePreview(wineryDetail.legalPersonCardF)">查看</span></el-descriptions-item>
          <el-descriptions-item label="法人身份证(反)"><span class="pointer"
              @click="picturePreview(wineryDetail.legalPersonCardB)">查看</span></el-descriptions-item>
          <el-descriptions-item label="公司存款账户"><span class="pointer"
              @click="picturePreview(wineryDetail.basicAccount)">查看</span></el-descriptions-item>
          <el-descriptions-item label="纳税人资格证"><span class="pointer"
              @click="picturePreview(wineryDetail.taxpayerQualiCert)">查看</span></el-descriptions-item>
          <el-descriptions-item label="商标注册证"><span class="pointer"
              @click="picturePreview(wineryDetail.tradeMarkLicense)">查看</span></el-descriptions-item>
          <el-descriptions-item label="销售授权书"><span class="pointer"
              @click="picturePreview(wineryDetail.marketingAuth)">查看</span></el-descriptions-item>
          <el-descriptions-item label="质检报告"><span class="pointer"
              @click="picturePreview(wineryDetail.qualityInspectReport)">查看</span></el-descriptions-item>
          <el-descriptions-item label="食品生产许可证"><span class="pointer"
              @click="picturePreview(wineryDetail.foodProductionPermit)">查看</span></el-descriptions-item>
          <el-descriptions-item label="食品经营许可证"><span class="pointer"
              @click="picturePreview(wineryDetail.foodBusinessLicense)">查看</span></el-descriptions-item>
          <el-descriptions-item label="生产单位营业执照"><span class="pointer"
              @click="picturePreview(wineryDetail.licenseProductionUnit)">查看</span></el-descriptions-item>
          <el-descriptions-item v-if="this.wineryDetail.importedGoods != 0" label="委托进口协议"><span class="pointer"
              @click="picturePreview(wineryDetail.entrustedImportAgreement)">查看</span></el-descriptions-item>
          <el-descriptions-item v-if="this.wineryDetail.importedGoods !== 0" label="报关单"><span class="pointer"
              @click="picturePreview(wineryDetail.customsDeclaration)">查看</span></el-descriptions-item>
          <el-descriptions-item v-if="this.wineryDetail.importedGoods !== 0" label="入境检验检疫"><span class="pointer"
              @click="picturePreview(wineryDetail.entryInspectQuarantine)">查看</span></el-descriptions-item>
        </el-descriptions>
      </div>

      <div>

      </div>
    </div>
    <!-- 图片预览 -->
    <picture-preview v-if="picturePreviewVisible" ref="picturePreview" />
  </div>
</template>

<script>
  import * as api from '@/api/winery/winery'
  import picturePreview from '@/components/PicturePreview'
  export default {
    components: {
      picturePreview
    },
    data() {
      return {
        wineryId: '', //酒企列表传参wineryId
        wineryDetail: {}, //接口酒企详情数据
        picturePreviewVisible: false // 预览图片弹窗
      }
    },
    created() {
      // 获取上页面跳转路由参数
      console.log(this.$route.query)
      this.wineryId = this.$route.query.wineryId
    },
    mounted() {
      this.getwineryDetail()
    },
    methods: {
      // 编辑
      edit(wineryId){
        this.$router.push({
            path: '/wineryEdit/enterWinery',
            query: {
              wineryId: wineryId
            }
          })
      },
      //设为异常
      wineryStatus0() {
        console.log(this.wineryDetail.wineryStatus)
        api.updateWineryStatus({
          wineryId: this.wineryId,
          wineryStatus: 0
        }).then(data => {

          this.$message({
            message: '设为异常成功！',
            type: 'success'
          });
          this.$nextTick(function() {
            this.wineryDetail.wineryStatus = 0
          })

        })
        this.getwineryDetail()
      },
      //恢复正常
      wineryStatus1() {
        console.log(this.wineryDetail.wineryStatus)
        api.updateWineryStatus({
          wineryId: this.wineryId,
          wineryStatus: 1
        }).then(data => {

          this.$message({
            message: '恢复正常成功！',
            type: 'success'
          });
          this.$nextTick(function() {
            this.wineryDetail.wineryStatus = 1
          })

        })
        this.getwineryDetail()
      },
      // 图片预览
      picturePreview(imgUrl) {
        console.log('======================')
        console.log(imgUrl)
        console.log('======================')
        this.picturePreviewVisible = true
        this.$nextTick(() => {
          this.$refs.picturePreview.init(imgUrl)
        })
      },
      getwineryDetail() {
        console.log('进入加载页面数据')
        api.winery(this.wineryId).then(data => {
          console.log(data)
          this.wineryDetail = data
          if (data.status == 1) {
            this.wineryDetail.status = "正常"
          } else {
            this.wineryDetail.status = "异常"
          }
          console.log('进入加载页面数据')
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .main {
    margin: 30px 40px;
    .magb {
      margin-bottom: 40px;
    }
    #s0{
      font-weight: bold;
      font-size: 30px;
      color: red;
      margin-left: 50px;
    }
    .bhead {
      height: 60px;
      line-height: 60px;
      font-weight: bold;
      font-size: 25px;
      padding-bottom: 20px;
      background-color: rgba(161, 161, 161, 0.6);
      border-radius: 10px;

    }
    .head {
      height: 60px;
      line-height: 60px;
      font-weight: bold;
      font-size: 25px;
      padding-bottom: 20px;
    }

    .base {
      .base_text {
        display: flex;
        justify-content: space-between;
      }

      .pointer {
        cursor: pointer;
      }

      ::v-deep .el-descriptions__table {
        height: 150px;
        font-size: 16px;

        .el-descriptions-item__label {
          color: black;
          font-weight: 600;
        }
      }
    }
  }
</style>
